package com.patrol.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.patrol.pojo.Fengxian;
import com.patrol.service.FengXianService;
import com.patrol.utils.Result;
import com.patrol.utils.TableMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@CrossOrigin
@RestController
@RequestMapping("/fengxian")
public class FengXianController {
    @Resource
    private FengXianService fengXianService;

    @PostMapping("/insert")
    public Result insert(Fengxian fengxian) {
        return fengXianService.insert(fengxian) ? Result.ok() : Result.fail();
    }

    @DeleteMapping("/delete/{workerId}")
    public Result delete(@PathVariable("workerId") int workerId) {
        return fengXianService.delete(workerId) ? Result.ok() : Result.fail();
    }

    @PutMapping("/update")
    public Result update(Fengxian fengxian) {
        return fengXianService.update(fengxian) ? Result.ok() : Result.fail();
    }

    @GetMapping("/select/{id}")
    public Result select(@PathVariable("id") int id) {
        return Result.ok(fengXianService.select(id));
    }

    @GetMapping("/selectPage")
    public TableMap selectPage(long page, long limit) {
        Page<Fengxian> fengxianPage = fengXianService.selectPage(page, limit);
        TableMap tableMap = new TableMap();
        tableMap.setData(fengxianPage.getRecords());
        tableMap.setCount(fengxianPage.getTotal());
        return tableMap;
    }

    @GetMapping("/selectPageByCondition")
    public TableMap selectPageByCondition(String startDate, String endDate) {
        return null;
    }

}
